//
//  ViewController.m
//  30503
//
//  Created by student on 16/4/5.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"
#import <CoreMotion/CoreMotion.h>
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *ball;
@property (nonatomic,strong) CMMotionManager *mm;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.mm=[[CMMotionManager alloc]init];
    if(self.mm.accelerometerAvailable)
    {
        self.mm.accelerometerUpdateInterval=0.1;
        [self.mm startAccelerometerUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMAccelerometerData * _Nullable accelerometerData, NSError * _Nullable error) {
            CGPoint p=self.ball.center;
            p.x+=(accelerometerData.acceleration.x)*10;
            p.y-=(accelerometerData.acceleration.y)*10;
            self.ball.center=p;
        }];
    }
}



@end
